<div class="box-page-container">
  <div class="box-page-header">
    <div class="title">Ресурсы</div>
    <div class="other-controls right">
    </div>
  </div>
  <div class="box-page-body">
    	<table class="table">
	      <thead>
	        <tr>
			  <th width="25px">ID</th>
			  <th width="120px">Ключевое имя</th>
			  <th width="230px">Описание</th>
			  <th width="200px">Модуль</th>
			  <th width="120px">Действие</th>
			  <th width="40px"></th>
			</tr>
	      </thead>
	      <tbody>
	        <?php foreach ($this->resources as $resource): ?>
			  <tr id="<?php echo $resource->id ?>">
				<td><?php echo $resource->id ?></td>
				<td><?php echo $resource->name ?></td>
				<td><?php echo $resource->description ?></td>
				<td><?php echo $resource->findParentRow('Model_Module')->title ?></td>
				<td><?php echo $resource->action ?></td>
				<td>
				  <div class="control-bar">
					<?php if ($resource->id != 1 && $resource->id != 2) :?>
					    <a href="/cp/resource/edit?id=<?php echo $resource->id ?>" title="Редактировать"><i class="icon-pencil"></i></a>
						<a href="#" title="Удалить" onclick="dDelete(this); return false;"><i class="icon-trash"></i></a>
					<?php endif; ?>
				  </div>
				</td>
			  </tr>
			<?php endforeach;?>
	      </tbody>
	    </table>
  </div>
  <div class="box-page-footer">
    <div class="box-controls">
      <div class="right">
       	<div class="btn"><button onclick="window.location = '/cp/resource/create'; return false;" class="primary">Создать ресурс</button></div>
      </div>
      <div id="progress" class="progress ajax-preloader-base"></div>
      <div id="control_text" class="box-controls-text"></div>
      <div class="clear-fix"></div>
    </div>
  </div>
  <div class="clear-fix"></div>
</div>
<script src="/js/jquery/jquery.js"></script>
<script>
function dDelete(el) {
	var title = $(el).parent().parent().parent().find('td').eq(2).text();
	var id = $(el).parent().parent().parent().attr('id');
	var ddel = new goog.ui.Dialog(null, true);
	// new page content
	var ddelc = '<div>Вы действительно хотите удалить ресурс <b>' + title + '</b>?</div>';
	ddel.setContent(ddelc);
	ddel.setTitle('Подтвердите удаление');
	ddel.setButtonSet(
		new goog.ui.Dialog.ButtonSet()
		.addButton({key: 'ok', caption: 'Да'}, true)
		.addButton({key: 'cancel', caption: 'Нет'}, false, true)
	);
	ddel.setVisible(true);
	$(ddel.getElement()).css({'width': '450px', 'left': (document.width / 2) - 225 + 'px'});
	goog.events.listen(ddel, goog.ui.Dialog.EventType.SELECT, function(e){
		if (e.key == 'ok') {
			window.location = '/cp/resource/delete?id=' + id;
		}
	});
}
</script>